#include <bits/stdc++.h>
#define INF 1e17
#define int  long long
using namespace std;

void solve()
{
    int n;
    cin >> n;
    int r = -1;
    for (int i = 30; i >= 0 && r == -1; --i)
    {
        if (n & (1LL << i))
        {
            for (int j = 0; j <= 30; ++j)
            {
                if ((n & (1LL << j)) == 0)
                {
                    int c = (1LL << j) | (1LL << i);
                    if (c < n)
                    {
                        r = c;
                        break;
                    }
                }
            }
        }
    }
    cout << r << endl;
}

signed main()
{
    int t1;
    cin >> t1;
    while (t1--)
    {
        solve();
    }
    return 0;
}